if ( typeof(mclog) == "undefined" ) {
    var mclog = {};
}
$( '.btn' ).click( function () {
    var form = $( this ).parents( 'form' );
    var obj = form.parent();
    if ( obj.attr( 'id' ) == 'db' ) {
        mclog._db( $( this ), obj );
    }
    if ( obj.attr( 'id' ) == 'admin' ) {
        mclog._install( form, obj );
    }
    return false;
});

mclog._db = function( obj, parent ){
    mclog.ajaxPOST( obj, function ( result ) {
        if ( result == 'unique' ) {
            window.setTimeout( function () {
                mclog.closeTip();
                $.jBox.confirm( "<p>当前数据库当中已经含有同样表前缀的数据表;</p>" +
                    "<p>您可以修改“表前缀”来避免删除旧的数据;</p>" +
                    "<p><b>继续安装会清空所有记录。</b></p>", "安装提示", function ( v ) {
                    if ( v == true ) {
                        mclog._next( parent );
                        return true;
                    }
                    return true;
                }, { top: '30%', buttons: { '继续安装': true, '取消': false} } );
            }, 2000 );
            return false;
        }
        if( result == 'success' ){
            window.setTimeout( function () { mclog.closeTip(); mclog._next( parent ); }, 3000 );
            return true;
        }
        window.setTimeout( function () { mclog.tip( result, 'error' ); }, 3000 );
    });
}

mclog._install = function( form, parent ){
    if ( !mclog.validate( form.find( 'input' ) ) ) {
        return;
    }
    mclog._next( parent );
    var data = $( "form" ).serialize();
    var url = form.attr( 'action' );
    $.post( url, data, function ( result ) {
        $( '.notice' ).html( result );
        if ( result.indexOf( '安装完成' ) != -1 ) {
            window.setTimeout( function () {
                mclog._next( parent.next( 'div' ) );
            }, 3000 );
            return true;
        }
    });
}

mclog._next = function( obj ){
    obj.slideUp( 500, function () {
        obj.next( 'div' ).slideDown( 500 );
    });
}